package com.example.jianzhioffer;

/**
 * Created by Quincy on 2018/9/10.
 * 输入一个链表，反转链表后，输出新链表的表头。
 */
public class fanzhuanList {

    public class ListNode{
        int val;
        ListNode next = null;
        ListNode(int val){
            this.val = val;
        }
    }

    public ListNode reverList(ListNode node){
        if (node == null){
            return null;
        }
        ListNode rHead  = null ;
        ListNode priorNode = null;
        ListNode currentNode = node;

        while (currentNode != null){
            ListNode nextNode = currentNode.next;
            if (currentNode.next == null)
                rHead = currentNode;
            currentNode.next = priorNode;
            priorNode = currentNode;
            currentNode = nextNode;
        }

        return rHead;
    }


}
